<?php
namespace App\HttpController;

use EasySwoole\Core\Http\Response;
use EasySwoole\Core\Http\Request;
use FastRoute\RouteCollector;

class Router extends \EasySwoole\Core\Http\AbstractInterface\Router
{
    public function register(RouteCollector $routeCollector)
    {
        // 权限规则
        $routeCollector->addRoute(['GET', 'POST', 'PUT', 'DELETE'], '/admin/rules[/{Id:\d+}]', '/Admin/Rules/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 菜单管理
        $routeCollector->addRoute(['GET', 'POST', 'PUT', 'DELETE'], '/admin/menus[/{Id:\d+}]', '/Admin/Menus/Index');
        $routeCollector->addRoute(['GET'], '/admin/Menus/Xml', '/Admin/Menus/Xml');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 角色管理
        $routeCollector->addRoute(['GET', 'POST', 'PUT', 'DELETE'], '/admin/groups[/{Id:\d+}]', '/Admin/Groups/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 用户管理
        $routeCollector->addRoute(['POST'], '/admin/users/deletes', '/Admin/Users/Deletes');
        $routeCollector->addRoute(['GET', 'DELETE', 'PUT', 'POST'], '/admin/users[/{Id:\d+}]', '/Admin/Users/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 图片验证码
        $routeCollector->addRoute(['GET'], '/verify', '/Admin/Verify/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 后台登录/退出
        $routeCollector->addRoute(['POST', 'DELETE', 'PUT'], '/admin/memberstatus[/{Id}]', '/Admin/MemberStatus/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 后台系统配置
        $routeCollector->addRoute(['GET', 'POST'], '/admin/configs', '/Admin/Configs/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 登录日志管理
        $routeCollector->addRoute(['GET', 'DELETE'], '/admin/signlogs[/{Id:\d+}]', '/Admin/SignLogs/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 操作日志管理
        $routeCollector->addRoute(['GET', 'DELETE'], '/admin/syslogs[/{Id:\d+}]', '/Admin/SysLogs/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 数据库操作
        $routeCollector->addRoute(['GET'], '/admin/database', '/Admin/DataBase/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 修改密码
        $routeCollector->addRoute(['POST'], '/admin/modifypass', '/Admin/Users/Modifypass');
        //-----------------------------------------------------------------------------------------------------------------------------
        //获取体检信息
        $routeCollector->addRoute(['GET'], '/home/userIndex[/{Id:\d+}]', '/Pudu/members/userIndex');

        //店铺对会员信息的修改
        $routeCollector->addRoute(['POST'], '/home/userEdit', '/Pudu/members/userEdit');

        //总后台 获取会员的体检信息
        $routeCollector->addRoute(['POST'], '/home/adminIndex', '/Pudu/members/adminIndex');
        
        //总后台 修改会员信息
        $routeCollector->addRoute(['POST'], '/home/adminUser', '/Pudu/members/adminUser');


        // 普度业务
        //-----------------------------------------------------------------------------------------------------------------------------
        // 会员管理
        //-----------------------------------------------------------------------------------------------------------------------------
        $routeCollector->addRoute(['GET', 'POST', 'PUT', 'DELETE'], '/pudu/members[/{Id:\d+}]', '/Pudu/Members/Index');
        $routeCollector->addRoute(['POST'], '/pudu/giveMoney', '/Pudu/Members/GiveMoney');
        
        //-----------------------------------------------------------------------------------------------------------------------------
        // 店铺管理
        //-----------------------------------------------------------------------------------------------------------------------------
        $routeCollector->addRoute(['GET', 'POST', 'PUT', 'DELETE'], '/pudu/shops[/{Id:\d+}]', '/Pudu/Shops/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 商品管理
        //-----------------------------------------------------------------------------------------------------------------------------
        $routeCollector->addRoute(['GET', 'POST', 'PUT', 'DELETE'], '/pudu/products[/{Id:\d+}]', '/Pudu/Products/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 订单管理
        //-----------------------------------------------------------------------------------------------------------------------------
        $routeCollector->addRoute(['GET', 'POST', 'PUT', 'DELETE'], '/pudu/orders[/{Id:\d+}]', '/Pudu/Orders/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 参数管理
        //-----------------------------------------------------------------------------------------------------------------------------
        $routeCollector->addRoute(['GET', 'POST', 'PUT', 'DELETE'], '/pudu/configs[/{Id:\d+}]', '/Pudu/Configs/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 用户记录管理
        //-----------------------------------------------------------------------------------------------------------------------------
        $routeCollector->addRoute(['GET', 'POST', 'PUT', 'DELETE'], '/pudu/memberrecords[/{Id:\d+}]', '/Pudu/MemberRecords/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 用户洗肠记录管理
        //-----------------------------------------------------------------------------------------------------------------------------
        $routeCollector->addRoute(['GET', 'POST', 'PUT', 'DELETE'], '/pudu/washrecords[/{Id:\d+}]', '/Pudu/WashRecords/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 用户提现记录管理
        //-----------------------------------------------------------------------------------------------------------------------------
        $routeCollector->addRoute(['GET', 'POST', 'PUT', 'DELETE'], '/pudu/membercashes[/{Id:\d+}]', '/Pudu/MemberCashes/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        
        // 店铺记录管理
        //-----------------------------------------------------------------------------------------------------------------------------
        $routeCollector->addRoute(['GET', 'POST', 'PUT', 'DELETE'], '/pudu/shoprecords[/{Id:\d+}]', '/Pudu/ShopRecords/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 店铺电子币申请记录管理
        //-----------------------------------------------------------------------------------------------------------------------------
        $routeCollector->addRoute(['GET', 'POST', 'PUT', 'DELETE'], '/pudu/shopemoney[/{Id:\d+}]', '/Pudu/ShopEmoney/Index');
        //-----------------------------------------------------------------------------------------------------------------------------
        // 获取页面配置文件
        //-----------------------------------------------------------------------------------------------------------------------------
        $routeCollector->addRoute(['GET'], '/jsonconfig', '/Common/JsonConfig/Index');
        //-----------------------------------------------------------------------------------------------------------------------------

        // 上传文件
        //-----------------------------------------------------------------------------------------------------------------------------
        $routeCollector->addRoute(['POST'], '/upload', '/Common/Upload/Index'); // 二进制
        $routeCollector->addRoute(['POST'], '/base64', '/Common/Upload/Base64');// base64
        //-----------------------------------------------------------------------------------------------------------------------------

        //-----------------------------------------------------------------------------------------------------------------------------
        // 404 和跨域 配置
        $this->setMethodNotAllowCallBack(function(Request $request ,Response $response){
            $a = $request->getMethod();
            if($a == 'OPTIONS'){    // option 方法不返回数据
                $response->withStatus(200);
                $response->end();
            }else{
                $res = json_encode(['code' => 404, 'msg' => '方法错误'], JSON_UNESCAPED_UNICODE);
                $response->withStatus(200);
                $response->write($res);
                $response->end();
            }
        });
    }
}
